<?php
	require_once('../libraryfiles/config.php');
	$content = 'receiveprescription.php';
	$include = '
	<script src="'.W_ROOT.'/js/common.js" type="text/javascript"></script>
	';    
	require_once TMP_USER_PATH;
	$user_id = $_SESSION['acc_id'];
	$view = isset($_GET['view'])?$_GET['view']:'';
	$oip_id = isset($_GET['oip'])?$_GET['oip']:'';
	$pharmacy_id = isset($_GET['pharmaId'])?$_GET['pharmaId']:0;	
	echo '
	<div class="row-fluid">
	<div class="box">
	<form name="frmlist" action="#" method="post">
	<div class="title">Receive Prescription</div>';
	switch($view){
		// detail
		case'detail':
		$order_id = isset($_GET['orderId'])?$_GET['orderId']:'';
		$sql_pha = "SELECT * FROM tblpharmacy WHERE user_id = $pharmacy_id";
		$result_pha = mysql_query($sql_pha);
		$row_pha = mysql_fetch_assoc($result_pha);
		$sql_d = "SELECT * FROM tblordernance WHERE ordernance_id = $order_id";
		$result_d = mysql_query($sql_d);
		if(dbNumRows($result_d)){
			$row_d = mysql_fetch_assoc($result_d);
			extract($row_d);
		?>
        
        <div class="center">
        <div style="padding-top:10px;">
        <div style="float:left; padding-left:10px;">
        <?php
		if($row_pha['pharmacy_image']!=""){
		?>
        <img src="<?php echo W_ROOT;?>/upload/<?php echo $row_pha['pharmacy_image']?>" class="border" /><br /><br />
       <strong> <?php echo getPharmaName($pharmacy_id)?></strong>
        <?php	
		}
		?>
        </div>
        <div style="float:right; width:200px;"><strong style="color:#666; font-size:12px;">Address: <?php echo $row_pha['address']?></strong></div>        
        </div>
        <div style="clear:both;">&nbsp;</div>
        <p align="center" style="font-size:20px;">Prescription</p>
        <div style="border-top:2px dotted #666; margin:0px 10px 0px 10px;">&nbsp;</div>
        <table cellpadding="5" cellspacing="5" border="0">
        <tbody>
        <tr>
        <td>Patient Name</td><td width="5">:</td><td width="200"><?php echo stripslashes($patient_name);?></td>
        <td align="left">Age</td><td width="5">:</td><td><?php echo $age;?></td>
        
        </tr>
        <tr>
        <td align="left">Sex</td><td width="5">:</td><td><?php echo $sex;?></td>
        <td>Weight</td><td width="5">:</td><td><?php echo $p_weight;?> kg</td>        
        </tr>
        <tr>
        <td align="left">Prescription Number<td width="5">:</td><td><?php echo $ordernance_code;?></td> 
        <td>Height</td><td width="5">:</td><td><?php echo $p_height;?> m</td>
        </tr>
        <tr>
        <td>Check Date</td><td width="5">:</td><td><?php echo $check_date;?></td>       
        <td>Doctor Name</td><td width="5">:</td><td><?php echo $doctor_name;?></td>
        </tr>
        <tr>
        <td valign="top">Note</td>
        <td width="5" valign="top">:</td>
        <td colspan="7">
        <?php echo stripslashes($note);?>
        </td>
        </tr>
        </tbody>
        </table>
        <br />
        <table cellpadding="0" cellspacing="0" border="0" id="displayPro" width="100%" style="padding:0px 2px 0px 2px;">
        <tbody>
            <tr id="displayTR">
            <td width="30" class="col3" align="center">N&deg;</td>
            <td width="80" align="center" class="col3">Image</td>
            <td align="center" width="200" class="col3">Product Name</td>
            <td align="center" width="70" class="col3">Quantity</td>
            <td align="center" class="col3" width="90">Unique Price</td>
            <td align="center" class="col3_1" width="90">Price</td>
            </tr>
            <?php
			$i=1;
			$sql = "SELECT * FROM tblproduct_in_ordernance WHERE order_id = $order_id";
			$result = mysql_query($sql);
			while($row = mysql_fetch_assoc($result)){
			$sql_img = "SELECT thumbnail FROM tblimage WHERE product_id = ".$row['product_id']." LIMIT 0,1";
				$result_img = mysql_query($sql_img);
				$row_img = mysql_fetch_assoc($result_img);
			if($row_img['thumbnail']!=""){
					$thumbnail_i = 	$row_img['thumbnail'];
				}else{
					$thumbnail_i = 	'no-image-small.png';
				}
			
			$sql_price = "SELECT unique_price, price FROM tblpro_order_in_pharmacy WHERE oip_id=".$oip_id." AND pio_id = ".$row['id'];
			$result_price = mysql_query($sql_price);
			$row_price = mysql_fetch_assoc($result_price);
			?>
            <tr>
            <td width="30" class="col4" align="center"><?php echo idFormat($i);?></td>
            <td width="80" align="center" class="col4"><img src="<?php echo W_S_IMAGES_DIR.$thumbnail_i; ?>" class="border" width="50" /></td>
            <td align="center" width="200" class="col4"><strong style="color:#06C;"><?php echo getProductName($row['product_id'])?></strong><br />
            <em style="color:#666;">Made in : <?php echo getCountryName($row['made_in']);?></em>
            </td>
            <td align="center" width="70" class="col4">
            <?php
			echo $row['quatity'];
			?>
            </td>
            <td align="center" class="col4">
            $ <?php echo $row_price['unique_price']?>
            </td>
            <td align="center" class="col4_1">
            $ <?php echo $row_price['price']?>
            </td>
	        </tr>
            <?php
			$i++;
			}
			?>
            <tr>
            <td colspan="5" align="right" style="padding-top:10px;"><strong>Total :</strong></td>
            <td align="center" style="padding-top:10px;">
            $ <?php echo getTotalPrice($order_id,$pharmacy_id)?>
            <?php updatePreStatus($order_id,$pharmacy_id); ?>
            </td>
            </tr>
            <tr>
            <td colspan="6" style="padding:10px 2px 10px 0px;" align="right">
            <input class="btn" type="button" name="btnback" value="Back" onclick="window.location.href='receiveprescription.php'" />
            </td>
            </tr>
        </tbody>
        </table>
        </div>
        <?php
		}
		break;
		
		// list
		default:
		$sql_l = "SELECT o.ordernance_id, o.user_id, o.ordernance_code, oip.* FROM tblordernance AS o, tblordernance_in_pharmacy as oip WHERE o.user_id = $user_id AND oip.ordernance_id = o.ordernance_id AND oip.pharma_check = 1 AND oip.isUserDeleted = 0 ORDER BY oip.reply_date DESC";
		$result_l = mysql_query($sql_l);
		?>
        <div class="center">
        <p align="right" style="padding-right:2px;">
        <input class="btn" type="button" name="btnunpublish" value="Delete" onclick="deleteSelectedPre(document.frmlist,'<?php echo htmlspecialchars(getAllGetParams(array('action','view')));?>','Prescription(s)','process');" />
        </p>
        <table cellpadding="0" cellspacing="0" border="0" id="displayPro" width="100%" style="padding:10px 2px 0px 2px;">
        <tbody>
            <tr>
            <td width="40" class="col3" align="center">N&deg;</td>
            <td width="20" class="col3" align="center"><input type="checkbox" name="chkall" id="chkall" onClick="checkAll(this.form,this.checked)" style="cursor:pointer;"></td>
            <td width="190" align="center" class="col3">Prescription Number</td>
            <td align="center" width="200" class="col3">Pharmacy Name</td>
            <td align="center" width="100" class="col3_1">View</td>
            </tr>
            <?php
			$i = 1;
			if(dbNumRows($result_l)){
			while($row_l = mysql_fetch_assoc($result_l)){
				extract($row_l);
			?>
            <tr>
            <td class="col4" align="center"><?php echo idFormat($i);?></td>
            <td class="col4" align="center"><input type="checkbox" name="id[]" value="<?php echo $id;?>"/>
            </td>
            <td class="col4" align="center"><?php echo $ordernance_code;?></td>
            <td class="col4" align="center"><?php echo getPharmaName($pharmacy_id)?><br />
            <span style="color:#666">Reply date: <?php echo $reply_date?></span>
            </td>
            <td class="col4_1" align="center">
            <?php
			if($user_check == "1"){
				$style = 'style="color:#666;"';
			}else{
				$style = 'style="color:#03F;"';
			}
			?>
            <a href="<?php $_SERVER['PHP_SELF']?>?view=detail&orderId=<?php echo $ordernance_id?>&amp;oip=<?php echo $id?>&amp;pharmaId=<?php echo $pharmacy_id?>" <?php echo $style; ?>>View</a>
            </td>
            </tr>
            <?php
			$i++;
			}
			}// end if
			else{
			?>
            <tr>
            <td colspan="4"><h3 align="center">No Prescription yet!</h3></td>
            </tr>
            <?php	
			}
			?>
        <tbody>
        </table>
        <br />
        </div>
        <?php
		break;
	}
?>
</form>
	</div><!--<div class="box">-->
</div><!--<div class="row-fluid">-->